package com.threeox.commonlibrary.entity.engine.event;

import android.content.Context;

import com.alibaba.fastjson.JSONObject;
import com.threeox.commonlibrary.entity.base.BaseObj;
import com.threeox.commonlibrary.util.ActivityUtils;
import com.threeox.commonlibrary.util.RegexHelper;
import com.threeox.utillibrary.util.ActivityHelper;
import com.threeox.utillibrary.util.EmptyUtils;
import com.threeox.utillibrary.util.res.StringHelper;

/**
 *
 * @ClassName: ActivityMsg
 *
 * @Description: TODO(Activity 配置信息)
 *
 * @author 赵屈犇
 *
 * @date 创建时间: 2017/7/4 17:56
 *
 * @version 1.0
 *
 */
public class ActivityMsg extends BaseObj {

    private JSONObject params;// 传递参数
    private Integer requestCode;// requestCode
    private Class activityClass;// Activity 的Class
    private String activityClassName;// Activity 的Class全名称
    private String paramsModelName;// 请求参数的模型名称

    private JSONObject paramsKeys;//可以替换的主键集合

    public void initData(StringHelper stringHelper) {
        try {
            RegexHelper.replaceJSONByRawName(paramsModelName, params);
            if (EmptyUtils.isNotEmpty(activityClassName)) {
                this.activityClassName = stringHelper.getStringText(activityClassName);
                this.activityClass = Class.forName(this.activityClassName);
            }
            paramsKeys = RegexHelper.getReplaceKeys(params);
        } catch (Exception e) {
        }
        RegexHelper.replaceSys(params);
    }

    public JSONObject getParams() {
        return params;
    }

    public void setParams(JSONObject params) {
        this.params = params;
    }

    public Integer getRequestCode() {
        return requestCode;
    }

    public void setRequestCode(Integer requestCode) {
        this.requestCode = requestCode;
    }

    public Class getActivityClass() {
        return activityClass;
    }

    public void setActivityClass(Class activityClass) {
        this.activityClass = activityClass;
    }

    public String getActivityClassName() {
        return activityClassName;
    }

    public void setActivityClassName(String activityClassName) {
        this.activityClassName = activityClassName;
    }

    public String getParamsModelName() {
        return paramsModelName;
    }

    public void setParamsModelName(String paramsModelName) {
        this.paramsModelName = paramsModelName;
    }

    /**
     * 初始化參數
     *
     * @param intent
     * @return
     * public void initParam(Intent intent) {
     *  RegexHelper.replace(this.params, this.paramsKeys, intent);
     * }
     *
     */

    /**
     * 初始化參數
     *
     * @param data
     */
    public void initParam(Object data) {
        RegexHelper.replace(this.params, this.paramsKeys, data);
     }

    /**
     * 启动Activity
     *
     * @param context
     */
    public void start(Context context) {
        if (null == getActivityClass()) {
            return;
        }
        ActivityHelper activityHelper = ActivityUtils.init(context, getActivityClass()).putIntent(params);
        if (null != getRequestCode()) {
            activityHelper.start(getRequestCode());
        } else {
            activityHelper.start();
        }
    }

}
